
var file = require('fs');



function add (){
    file.writeFileSync('input.txt',"欢迎来到升学记");

}
function read(){
    var res =file.readFileSync('input.txt','utf-8');
    console.log(res);
}
function addSteam(){
    var writeStream = file.createWriteStream('inputStream.txt');

    writeStream.write('欢迎来到升职技 流方式写入');
    writeStream.on('finish',function(){
        console.log('写入完成');
    })
    writeStream.on('error',function(err){
        console.log('写入失败'+err.stack);
    })

}
function readStream(){
    var readStream = file.createReadStream('inputStream.txt');
    var data = "";
    readStream.on('data',function(chunk){
        data+=chunk;
        
    })
    
    readStream.on('end',function(){
        console.log(data);
    })
    readStream.on('error',function(err){
        console.log(err.stack);
    })
    console.log('read end');
}

readStream();